package leetcode_401_500;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

public class LeeCode_500 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(findWords(new String[]{"Hello", "Alaska", "Dad", "Peace"})));
    }
    private static String[] findWords(String[] words) {
        String[] map = new String[]{"qwertyuiopQWERTYUIOP", "asdfghjklASDFGHJKL","zxcvbnmZXCVBNM"};
        List<String> list = new ArrayList<>();
        for (String word : words) {
            int index = 0;
            for (int i = 0; i < 3; i++) {
                if (map[i].contains(word.charAt(0) + "")){
                    index = i;
                    break;
                }
            }
            boolean flag = true;
            for (int i = 1; i < word.length(); i++) {
                if (!map[index].contains(word.charAt(i) + "")){
                    flag = false;
                    break;
                }
            }
            if (flag){
                list.add(word);
            }
        }
        String[] ans = new String[list.size()];
        int i = 0;
        while (i < ans.length){
            ans[i] = list.get(i);
            i++;
        }
        return ans;
    }
}
